/*
 * rTree3D.h
 *
 *  Created on: Jun 27, 2011
 *      Authors: Lane Aasen, Nikholas Gaffney, Michael Rosenberger, Dylan Swiggett
 */

#include "boid.h"
#include "vector3D.h"

#define MAXCOUNT 3

/*
 * Store all data within a single node of the tree.
 * Can have either Boids or more rTree nodes as children.
 */
typedef struct {
	Boid* boids[MAXCOUNT + 1];
	struct rTree *subTrees;
	int boidCount, treeCount;
	int leaf;
	Vector3D p1, p2;
} rTree;

/*
 * Generate top level node for a full RTree to be built off of.
 */
rTree* initRTree();

/*
 * Go through the specified tree recursively, resizing all rectangles to fit all of their children.
 */
void expandRTree(rTree *tree);

/*
 * Add the boid to the boid to the specified rTree, either by putting it in directly or recursing.
 */
void subdivideRTree(rTree *tree);

void addBoidRTree(rTree *tree, Boid boid);

/*
 * Reevaluate the bounds of all boxes within the tree.
 * Resize them to fit all child Boids or subTrees.
 */
void refreshRTree(rTree *tree);

/*
 * Fully rebuild the tree - pack all Boids into the smallest area of boxes possible.
 * More expensive than refresh, but much more effective.
 */
void rebuildRTree(rTree *tree);

/*
 * Convert a leaf rTree into a branch rTree containing a new leaf rTree for each of its previous child Boids.
 */
